package com.nuoniu.sibanyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.SendSms;
import com.nuoniu.sibanyun.mapper.SendSmsMapper;
import com.nuoniu.sibanyun.service.ISendSmsService;
import com.nuoniu.sibanyun.utils.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

/**
 * <p>
 * 短信记录 服务实现类
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-11
 */
@Service
public class SendSmsServiceImpl extends ServiceImpl<SendSmsMapper, SendSms> implements ISendSmsService {

    @Autowired
    private SendSmsMapper sendSmsMapper;
    @Autowired
    private HttpServletRequest request;

    @Override
    public List<SendSms> getSendSmsList(String userPhone) {
        Map<String, String > param = new HashMap<>();
        param.put("userPhone", userPhone);
        param.put("ip", IpUtil.getClientIp(request));
        return sendSmsMapper.getSendSmsList(param);
    }

    @Override
    public Integer countByCompany(Integer companyId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("company_id", companyId);
        wrapper.eq("date(create_date)", LocalDate.now());
        return count(wrapper);
    }
}
